package com.heima.article.controller.v1;

import com.heima.article.service.ArticleInfoService;
import com.heima.common.exception.LeadNewsException;
import com.heima.model.article.dto.ArticleInfoDto;
import com.heima.model.common.dto.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author Ronaldo
 * @date 2021/8/13
 */
@RestController
@RequestMapping("/api/v1/article")
@Slf4j
public class ArticleInfoController {

    @Autowired
    private ArticleInfoService articleInfoService;

    @PostMapping("/load_article_info")
    public ResponseResult loadInfo(@RequestBody ArticleInfoDto articleInfoDto){

        log.info("get article info by articleId",articleInfoDto);

        if (Objects.isNull(articleInfoDto)){
            throw new LeadNewsException(AppHttpCodeEnum.PARAM_INVALID);
        }
        return articleInfoService.getArticleInfoById(articleInfoDto);
    }
}
